<template>
  <div class="soBill">
    <div class="publicSearch">
      <div class="searchBar" :style="{ height: isMoreSearch ? 'auto' : '' }">
        <el-button-group>
          <el-button @click="getSoData" size="mini" icon="el-icon-search">查询</el-button>
          <el-button @click="clearSearchData" size="mini" icon="el-icon-refresh">重置</el-button>
        </el-button-group>
        <!-- <div>
            <span>SO类型</span>
            <el-select v-model="searchData.soType" size="mini" filterable placeholder="请选择SO类型" clearable>
                <el-option
                        v-for="item in soBillTypes"
                        :key="item.dataDictDetailId"
                        :label="item.dictValue"
                        :value="item.dataDictDetailId">
                </el-option>
            </el-select>
        </div>
        <div>
            <span>单据来源</span>
            <el-select v-model="searchData.billSource" size="mini" filterable placeholder="请选择单据来源" clearable>
                <el-option :key="1" label="新建" :value="1">新建</el-option>
                <el-option :key="2" label="合并" :value="2">合并</el-option>
                <el-option :key="3" label="调拨" :value="3">调拨</el-option>
            </el-select>
        </div>-->
        <!-- <div>
          <span>单号</span>
          <el-input v-model="searchData.billNo" size="mini" placeholder="请输入单号" clearable></el-input>
        </div> -->
        <div>
          <span>排产计划</span>
          <el-input
              v-model="searchData.expectTimeFm"
              size="small"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请输入排产计划时间"
              clearable
          ></el-input>
        </div>
        <div>
          <span>出库任务单号</span>
          <el-input v-model="searchData.billNo" size="mini" placeholder="请输入生产任务单号" clearable></el-input>
        </div>
        <div>
          <span>履约号</span>
          <el-input v-model="searchData.tradeNo" size="mini" placeholder="请输入履约号" clearable></el-input>
        </div>
        <!-- <div>
            <span>产品型号查询</span>
            <el-input
             v-model="searchData.model"
             size="mini"
             placeholder="请输入产品型号"
             clearable
             ></el-input>
        </div>-->
        <!-- <div>
          <span>状态</span>
          <el-select
              v-model="searchData.state"
              size="mini"
              filterable
              placeholder="状态"
              clearable
          >
            <el-option
                key="0"
                value="0"
                style="color: #909399"
                label="新建"
            ></el-option>
            <el-option
                key="1"
                value="1"
                style="color: #909399"
                label="已合并"
            ></el-option>
            <el-option
                key="3"
                value="3"
                style="color: #f56c6c"
                label="缺货"
            ></el-option>
            <el-option
                key="4"
                value="4"
                style="color: #409eff"
                label="已分配"
            ></el-option>
            <el-option
                key="-1"
                value="-1"
                style="color: #f56c6c"
                label="取消"
            ></el-option>
            <el-option
                key="6"
                value="6"
                style="color: #543044"
                label="拣货完成"
            ></el-option>
            <el-option
                key="7"
                value="7"
                style="color: #e6a23c"
                label="已复核"
            ></el-option>
            <el-option
                key="8"
                value="8"
                style="color: #67c23a"
                label="已发运"
            ></el-option>
          </el-select>
        </div>-->
        <!-- <div>
          <span>承运方</span>
          <el-select
              v-model="searchData.carrierId"
              size="mini"
              filterable
              placeholder="请选择承运方"
              clearable
          >
            <el-option
                v-for="(item, index) in carriers"
                :key="index"
                :label="item.carrierName"
                :value="item.carrierId"
            >
            </el-option>
          </el-select>
        </div>
        <div>
          <span>审核状态</span>
          <el-select
              v-model="searchData.state"
              size="mini"
              filterable
              placeholder="请选择审核状态"
              clearable
          >
            <el-option
                v-for="(item, index) in reviewStates"
                :key="index"
                :label="item.label"
                :value="item.value"
            >
            </el-option>
          </el-select>
        </div>-->
        <!-- <div>
          <span>货主</span>
          <el-select
              v-model="searchData.organizationId"
              size="mini"
              filterable
              placeholder="请选择货主"
              clearable
          >
            <el-option
                v-for="(item, index) in organizations"
                :key="index"
                :label="item.organizationName"
                :value="item.organizationId"
            >
            </el-option>
          </el-select>
        </div>-->
        <!-- <div>
          <span>客户</span>
          <el-select
              v-model="searchData.customerId"
              size="mini"
              filterable
              placeholder="请选择客户"
              style="width: 70%"
          >
            <el-option
                v-for="(item, index) in customers"
                :key="index"
                :label="item.customerName"
                :value="item.customerId"
            >
            </el-option>
          </el-select>
        </div>-->
        <div>
          <span>部门</span>
          <el-input v-model="searchData.deptName" size="mini" placeholder="请输入部门名称" clearable></el-input>
        </div>
        <div>
          <span>排产日期时间段</span>
          <el-date-picker
              v-model="searchData.expectTimeFmArr"
              size="mini"
              type="daterange"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
          ></el-date-picker>
        </div>

        <div>
          <span>创建时间</span>
          <el-date-picker
              v-model="searchData.createTimeArr"
              size="mini"
              type="daterange"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
          >
          </el-date-picker>
        </div>
        <!-- <div>
          <span>要求交货时间</span>
          <el-date-picker
              v-model="searchData.deliveryTimeArr"
              size="mini"
              type="daterange"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
          >
          </el-date-picker>
        </div>-->
        <!-- <div>
          <span>预期发货时间</span>
          <el-date-picker
              v-model="searchData.expectTimeFmArr"
              size="mini"
              type="daterange"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
          >
          </el-date-picker>
        </div>
        <div>
          <span>优先级</span>
          <el-input
              v-model="searchData.orderNo"
              size="mini"
              placeholder="请输入优先级"
              clearable
          ></el-input>
        </div>-->
        <div>
          <span>关键字搜索</span>
          <el-input
              v-model="searchData.keyWords"
              size="mini"
              title="自定义字段/创建人/备注"
              placeholder="自定义字段/创建人/备注"
              clearable
          ></el-input>
        </div>
      </div>
      <span
          class="moreSearchBtn"
          :class="isMoreSearch ? 'el-icon-caret-top' : 'el-icon-caret-bottom'"
          @click="isMoreSearch = !isMoreSearch"
      ></span>
    </div>
    <div class="headerBtns">
<!--      <el-button-->
<!--          size="mini"-->
<!--          type="primary"-->
<!--          round-->
<!--          icon="iconfont icon-xinzeng"-->
<!--          @click="$router.push({ name: 'createSoBill' })"-->
<!--      >新增</el-button>-->
      <!-- <el-button
        size="mini"
        type="success"
        round
        icon="iconfont icon-hebing"
        @click="commitMerge"
        :disabled="mergeFlg"
        title="请勾选相同[仓库/货主/客户]的订单"
      >
        合并
      </el-button>-->
      <el-button
          size="mini"
          type="success"
          round
          icon="iconfont icon-hebing"
          @click="commitMerge"
          :disabled="mergeFlg"
          title="请勾选相同[生产任务单号/部门]的任务"
      >波次合并</el-button>
      <el-button
          size="small"
          type="warning"
          round
          icon="iconfont icon-jianhuo"
          :disabled="pickFlg"
          @click="createPickTask"
      >拣货分配</el-button>

      <el-button
          size="small"
          type="primary"
          round
          :disabled="userFlg"
          @click="dialogAllocate = true"
      >
        分配仓管员
      </el-button>


      <!-- <el-button
        class="rightFloat"
        size="mini"
        type="info"
        plain
        round
        icon="iconfont icon-backup"
        @click="commitFile"
        :disabled="multipleSelection.length <= 0"
      >
        归档
      </el-button>-->
      <!-- <el-button
          size="mini"
          type="primary"
          round
          icon="iconfont icon-xinzeng"
          @click="downloadModel()"
      >
        下载模板
      </el-button>
      <el-button
          size="mini"
          type="primary"
          round
          icon="iconfont icon-xinzeng"
          @click="upLoad()"
      >
        上传
      </el-button
      >
      <input type="file" id="file" class="mgl-10 w180"/>-->
      <!-- <el-button
        size="mini"
        type="primary"
        round
        icon="iconfont icon-xinzeng"
        @click="setCarrier()"
      >
        分配承运人
      </el-button>-->
      <el-date-picker
          style="margin-left: 800px"
          v-model="date"
          value-format="yyyy-MM-dd"
          type="date"
          placeholder="选择日期时间"
          align="right"
          :picker-options="pickerOptions"
      ></el-date-picker>
      <el-button
          style="margin-left: 20px"
          size="mini"
          type="primary"
          round
          @click="saveBillOutInfo()"
          icon="iconfont icon-wuliu"
      >获取出库数据</el-button>

      <!-- <el-button
          size="mini"
          class="rightFloat"
          type="primary"
          round
          icon="iconfont icon-wuliu"
          :disabled="multipleSelection.length != 1"
          @click="sendOut()"
      >整单发货</el-button> -->

      <!-- <el-button
          size="mini"
          type="primary"
          round
          icon="iconfont icon-wuliu"
          @click="batch()"
      >
        批量拣货
      </el-button>-->
    </div>


    <div class="tableBox">
      <el-table
          v-loading="loading.masterTable"
          highlight-current-row
          :data="soBills"
          @selection-change="handleSelectionChange"
          style="width: 100%"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <!-- <el-table-column
                 fixed="left"
                 type="index"
                 width="50">
        </el-table-column>-->
        <el-table-column show-overflow-tooltip prop="typeName" label="任务类型" min-width="120"></el-table-column>

        <el-table-column
            fixed="left"
            show-overflow-tooltip
            prop="billNo"
            label="出库任务单号"
            min-width="150"
        >
          <template slot-scope="scope">
            <span
                class="textBtn"
                @click="$router.push({ name: 'soBillDetail', params: scope.row })"
            >{{ scope.row.billNo }}</span>
          </template>
        </el-table-column>
        <!--        <el-table-column-->
        <!--            show-overflow-tooltip-->
        <!--            prop="orderBillNo"-->
        <!--            label="生产领料单号"-->
        <!--            min-width="150"-->
        <!--        >-->
        <!--        </el-table-column>-->
        <el-table-column show-overflow-tooltip prop="categoryName" label="类型" min-width="150">
          <!--          <template slot-scope="scope">-->
          <!--            {{ scope.row.billType===88? scope.row.orderBillNo :""}}-->
          <!--          </template>-->
        </el-table-column>
        <!-- <el-table-column
          fixed="left"
          show-overflow-tooltip
          prop="shipBillCode"
          label="物流单号"
          min-width="150"
        >
        </el-table-column>-->

        <!--        <el-table-column-->
        <!--            show-overflow-tooltip-->
        <!--            prop="soStructure"-->
        <!--            label="sku种类"-->
        <!--            min-width="100"-->
        <!--        >-->
        <!--        </el-table-column>-->

        <!-- <el-table-column
                show-overflow-tooltip
                prop="billSource"
                label="单据来源"
                width="80">
            <template slot-scope="scope">
                <span v-if="scope.row.billSource === 1">新建</span>
                <span v-if="scope.row.billSource === 2"  >合并</span>
                <span v-if="scope.row.billSource === 3"  >调拨</span>
            </template>
        </el-table-column>-->
        <!-- <el-table-column
                show-overflow-tooltip
                prop="state"
                label="审核状态"
                width="80">
            <template slot-scope="scope">
                <el-tag v-for="(item,index) in reviewStates" :key="index" v-if="scope.row.state === item.value" :type="item.type">
                    {{item.label}}
                </el-tag>
            </template>
        </el-table-column>-->
        <el-table-column sortable show-overflow-tooltip prop="state" label="状态" width="120">
          <template slot-scope="scope">
            <el-tag :type="scope.row.state | statusFilter">{{ scope.row.state | formatStata }}</el-tag>
          </template>
        </el-table-column>

        <el-table-column sortable show-overflow-tooltip prop="tradeNo" label="履约号" min-width="180"></el-table-column>

        <!-- <el-table-column
            show-overflow-tooltip
            prop="customerName"
            label="客户"
            min-width="100"
        >
          <template slot-scope="scope">
            <span
                class="textBtn"
                @click="$parent.showPublicModal(scope.row.customerId, 'customer')"
            >{{ scope.row.customerName }}</span
            >
          </template>
        </el-table-column>-->

        <el-table-column
            sortable
            show-overflow-tooltip
            prop="expectTimeFm"
            label="排产计划时间"
            width="130"
        >
          <!--            <template slot-scope="scope">-->
          <!--                <span v-if="scope.row.expectTimeFm !== undefined ">{{scope.row.expectTimeFm.substr(5,11)}}</span>-->
          <!--            </template>-->
        </el-table-column>

        <!-- <el-table-column
          show-overflow-tooltip
          prop="weight"
          label="重量"
          min-width="100"
        >
        </el-table-column>-->

        <el-table-column show-overflow-tooltip prop="deptName" label="部门" min-width="150"></el-table-column>
        <el-table-column show-overflow-tooltip prop="supplierName" label="供应商" min-width="150"></el-table-column>

        <!-- <el-table-column
            show-overflow-tooltip
            prop="organizationName"
            label="货主"
            min-width="100"
        >

          <template slot-scope="scope">
            <span
                class="textBtn"
                @click="
                $EventBus.$emit(
                  'showPublicModal',
                  scope.row.organizationId,
                  'organization'
                )
              "
            >{{ scope.row.organizationName }}</span
            >
          </template>
        </el-table-column>-->
        <!-- <el-table-column
                show-overflow-tooltip
                prop="linkMan"
                label="收货人"
                width="80">
        </el-table-column>
        <el-table-column

                show-overflow-tooltip
                prop="carrierName"
                label="承运方"
                width="100">
        </el-table-column>
        <el-table-column
                sortable
                show-overflow-tooltip
                prop="deliveryTime"
                label="要求交货时间"
                width="110">
            <template slot-scope="scope">
                <span v-if="scope.row.deliveryTime != undefined ">{{scope.row.deliveryTime.substr(5,11)}}</span>

            </template>
        </el-table-column>
        <el-table-column
                sortable
                show-overflow-tooltip
                prop="expectTimeFm"
                label="预发时间FM"
                width="110">
            <template slot-scope="scope">
                <span v-if="scope.row.deliveryTime != undefined ">{{scope.row.expectTimeFm.substr(5,11)}}</span>

            </template>
        </el-table-column>
        <el-table-column
                sortable
                show-overflow-tooltip
                prop="expectTimeTo"
                label="预发时间TO"
                width="110">
            <template slot-scope="scope">
                <span v-if="scope.row.deliveryTime != undefined ">{{scope.row.expectTimeTo.substr(5,11)}}</span>

            </template>
        </el-table-column>
        <el-table-column
                show-overflow-tooltip
                prop="orderNo"
                label="优先级"
                width="80">
        </el-table-column>
        <el-table-column
                show-overflow-tooltip
                v-for="(item,index) in soUdfHs"
                :key="index"
                :prop="item.paramCode"
                :label="item.value"
                width="180">
        </el-table-column>-->
        <el-table-column show-overflow-tooltip prop="waveCode" label="波次号" min-width="150"></el-table-column>
        <el-table-column sortable show-overflow-tooltip prop="memo" label="备注" min-width="180"></el-table-column>
        <el-table-column sortable show-overflow-tooltip prop="assUserName" label="仓管员" min-width="180"></el-table-column>
        <el-table-column show-overflow-tooltip prop="createTime" label="创建时间" min-width="100">
          <template slot-scope="scope">{{ scope.row.createTime.substr(5, 11) }}</template>
        </el-table-column>
        <el-table-column show-overflow-tooltip prop="createUserName" label="创建人" min-width="100">
          <template slot-scope="scope">
            <el-button
                @click="
                $EventBus.$emit(
                  'showPublicModal',
                  scope.row.createUserId,
                  'account'
                )
              "
                type="text"
            >{{ scope.row.createUserName }}</el-button>
          </template>
        </el-table-column>
        <!-- <el-table-column
          show-overflow-tooltip
          prop="priority"
          label="优先级"
          min-width="100"
        >
        </el-table-column>
        <el-table-column
          fixed="right"
          show-overflow-tooltip
          prop="createUserName"
          label="操作"
          min-width="100"
        >
          <template slot-scope="scope">
            <el-button
              @click="adjustLevel(scope.row.soMasterId)"
              type="danger"
              size="small"
            >
              优先级
            </el-button>
          </template>
        </el-table-column>-->
        <!--        <el-table-column-->
        <!--            show-overflow-tooltip-->
        <!--            v-for="(item,index) in soUdfHs"-->
        <!--            :key="index"-->
        <!--            :prop="item.paramCode"-->
        <!--            :label="item.value"-->
        <!--            width="160">-->
        <!--        </el-table-column>-->
        <!-- <el-table-column
                prop="manufactureType"
                label="生成加工单"
                width="100">
            <template slot-scope="scope">
                <span>{{scope.row.manufactureType === 1 ? '是' : '否'}}</span>
            </template>
        </el-table-column>

         <el-table-column
                fixed="left"
                show-overflow-tooltip
                prop="mergeNo"
                label="合并单号"
                width="80">
            <template slot-scope="scope">
                <span class="textBtn"
                      @click="$router.push({name: 'soBillDetail',params: {billNo: scope.row.mergeNo}})">{{scope.row.mergeNo}}</span>
                <span></span>
            </template>
        </el-table-column>-->
      </el-table>
      <!--      弹框-->
      <el-dialog title="批量拣货" :visible.sync="dialogVisible" width="50%" :before-close="resetForm">
        <div>
          任务号
          <div class="warp" v-for="(item, index) in billNoList" :key="index">
            <div
                style="width: 45%"
                class="textBtn"
                @click="$router.push({ name: 'soBillDetail', params: item })"
            >{{ item }}</div>
          </div>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="resetForm()">取 消</el-button>
          <el-button type="primary" @click="commitForm()">生成配料单</el-button>
        </span>
      </el-dialog>



      <el-dialog
          title="分配仓管员"
          :visible.sync="dialogAllocate"

          width="500px"
          :close-on-click-modal="false"
      >
        <el-form>
          <el-select v-model="userId" filterable placeholder="请选择">
            <el-option
                v-for="item in users"
                :key="item.userId"
                :label="item.userName"
                :value="item.userId"
            >
            </el-option>
          </el-select>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogAllocate = false">取 消</el-button>
          <el-button type="primary" @click="commitAllocateUser()"
          >确 定</el-button
          >
        </div>
      </el-dialog>

      <el-pagination
          class="pagination-bottom"
          style="text-align: right"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
          :current-page.sync="searchData.pageNum"
          :page-size="searchData.pageSize"
          :page-sizes="[10, 30, 50, 100]"
          layout="sizes,total, prev, pager, next, jumper"
          :total="searchData.total"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import { mapState } from "vuex";

export default {
  name: "elseSo",
  data() {
    return {
      pickerOptions: {
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            }
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            }
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            }
          }
        ]
      },
      date: "",
      loading: {
        masterTable: true
      },
      billNoList: [],
      unLoadData: {
        model: "",
        wareId: 111,
        insertType: 111
      },
      dialogVisible: false,
      isMoreSearch: false,
      dialogAllocate: false,
      userId: '',
      searchData: {

        pageNum: 1,
        pageSize: 10,
        total: null,
        keyWords: "",

        wareId: PF.getLocal("wareId", "number"),
        state: null,
        organizationId: null,
        customerId: null,
        billSource: null,
        carrierId: null,
        soType: 29,
        createTimeArr: [],

        startCreateTime: "",
        endCreateTime: "",
        deliveryTimeArr: [],
        startDeliveryTime: "",
        endDeliveryTime: "",
        expectTimeFmArr: [],
        startExpectTimeFm: "",
        endExpectTimeTo: "",
        orderBillNo: "",
        tradeNo: "",
        expectTimeFm: "",
        billNo: "",
        mergeNo: "",
        orderNo: "",
        billnoArr: "",
        deptName: ""
      },
      users: [],
      soBills: [],
      formLabelWidth: "120px",
      soUdfHs: [],
      organizations: [],
      customers: [],
      soBillTypes: [],
      carriers: [],
      multipleSelection: []
    };
  },
  filters: {
    // el-tag类型转换
    statusFilter(status) {
      const statusMap = {
        0: "info", //danger  success  warning  info
        1: "",
        3: "danger",
        4: "",
        6: "success",
        7: "success",
        8: "success",
        12: "danger",
      };
      return statusMap[status];
    },
    // 质检结果显示转换
    formatStata(status) {
      const statusMap = {
        0: "新建",
        1: "已合并",
        3: "部分分配",
        4: "已分配",
        6: "拣货完成",
        7: "已复核",
        8: "已发运",
        12:"合单拆分",
      };
      return statusMap[status];
    }
  },
  computed: {


    // //分配仓管员
    // userFlg() {
    //   let newItem = [];
    //   this.multipleSelection.forEach((item) => {
    //     if (item.state === 0) {
    //       newItem.push(item);
    //     }
    //   });
    //
    //   return [...new Set(newItem)].length !==this.multipleSelection.length;
    // },


    ...mapState(["reviewStates"]),
    mergeFlg() {
      let list = PF.JSON(this.multipleSelection);


        // 只能合并 88类型跟新建的单子或者是合单拆分的单子
        for (let i = 0; i < list.length; i++) {
          if ( list[i].state !== 0?list[i].state!=12:false) {
            return true;
          }
        }

    },
    pickFlg() {
      let list = PF.JSON(this.multipleSelection);

      // 拣货分配（只允许非88类型进行分配）
      for (let i = 0; i < list.length; i++) {
        if (list[i].billType == 88) {
          return true;
        }
      }
    }
  },
  methods: {

    //分配仓管员
    commitAllocateUser() {
      let soMasterIds = [];
      console.log(this.multipleSelection)
      this.multipleSelection.forEach((item) => {
        soMasterIds.push(item.soMasterId);

      });
      IOT.getServerData("/so/masters/suggest", "get", {soMasterIds: soMasterIds.join(","),userId:this.userId }, ret => {
        if (ret.code === 200) {
          IOT.tips("优先级调整成功！", "success");
          this.dialogAllocate = false;
          this.getSoData();
        } else {
          IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
        }
      });
    },

    commitForm() {
      console.log("this.billNoList", this.billNoList);
    },
    resetForm() {
      // 重置
      // this.billNoList = [];
      this.dialogVisible = false;
    },

    adjustLevel(soMasterId) {
      IOT.getServerData("/so/masters/priority", "get", { soMasterId }, ret => {
        if (ret.code === 200) {
          IOT.tips("优先级调整成功！", "success");
          this.getSoData();
        } else {
          IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
        }
      });
    },
    handleSizeChange(val) {
      this.searchData.pageSize = val;
      this.getSoData();
    },
    downloadModel() {
      window.open("/model/SoImport.xls");
    },
    upLoad() {
      var formData = new FormData();
      formData.append("model", document.querySelector("#file").files[0]); //上传一个files对象
      formData.append("wareId", 111); //需要上传的多个参数

      IOT.upLoadFile(
          "/so/masters/importSoBills",
          "post",
          formData,
          ret => {},
          true
      );
    },
    handleCurrentChange(val) {
      this.searchData.pageNum = val;
      this.getSoData();
    },
    clearSearchData() {
      this.searchData.keyWords = "";
      this.searchData.state = null;
      this.searchData.organizationId = null;
      this.searchData.customerId = null;
      this.searchData.soType = null;
      this.searchData.billSource = null;
      this.searchData.carrierId = null;
      this.searchData.createTimeArr = [];
      this.searchData.startCreateTime = "";
      this.searchData.endCreateTime = "";
      this.searchData.deliveryTimeArr = [];
      this.searchData.startDeliveryTime = "";
      this.searchData.endDeliveryTime = "";
      this.searchData.expectTimeFmArr = [];
      this.searchData.startExpectTimeFm = "";
      this.searchData.endExpectTimeTo = "";
      this.searchData.billNo = "";
      this.searchData.mergeNo = "";
      this.searchData.orderNo = "";
      this.searchData.expectTimeFm = "";
      this.searchData.tradeNo = "";
      this.searchData.billnoArr = "";
      this.searchData.deptName = "";
    },
    getSoData() {
      let searchData = PF.JSON(this.searchData);
      console.log(JSON.stringify(searchData));
      if (searchData.createTimeArr.length > 0) {
        searchData.startCreateTime = searchData.createTimeArr[0];
        searchData.endCreateTime = searchData.createTimeArr[1];
      }
      if (searchData.deliveryTimeArr.length > 0) {
        searchData.startDeliveryTime = searchData.deliveryTimeArr[0];
        searchData.endDeliveryTime = searchData.deliveryTimeArr[1];
      }
      if (searchData.expectTimeFmArr.length > 0) {
        searchData.startExpectTimeFm = searchData.expectTimeFmArr[0];
        searchData.endExpectTimeTo = searchData.expectTimeFmArr[1];
      }
      let that = this;
      that.loading.masterTable = true;
      IOT.getServerData("/so/masters/list", "get", searchData, ret => {
        that.loading.masterTable = false;
        if (ret.code === 200) {
          this.soBills = ret.rows;
          this.searchData.total = ret.total;
          this.searchData.pageNum = ret.pageNumber;

          IOT.hideOverlay();
        } else {
          IOT.hideOverlay();
          IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
        }
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
      // console.log(JSON.stringify(this.multipleSelection));
    },
    commitFile() {
      IOT.showOverlay("保存中，请稍等...");
      let list = PF.JSON(this.multipleSelection);
      console.log(JSON.stringify(list));
      let billNos = [];
      for (let i = 0; i < list.length; i++) {
        billNos.push(list[i].billNo);
      }
      IOT.getServerData(
          "/so/masters/file",
          "post",
          { billNos: billNos },
          ret => {

            if (ret.code === 200) {
              IOT.tips("归档成功！", "success");
              this.multipleSelection = [];
              this.getSoData();
            } else {
              IOT.hideOverlay();
              IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
            }
          }
      );
    },
    createPickTask() {
      let list = PF.JSON(this.multipleSelection);
      let billNos = [];
      for (let i = 0; i < list.length; i++) {
        //不是新建或部分分配状态的跳过
        if (list[i].state != 0 && list[i].state != 3) {
          continue;
        }
        billNos.push(list[i].billNo);
      }
      if (billNos.length > 0) {
        IOT.showOverlay("分配中，请稍等...");

        IOT.getServerData(
            "/pick/tasks/autoCreatePickTask",
            "post",
            { billNos: billNos },
            ret => {
              IOT.hideOverlay();
              if (ret.code === 200) {
                IOT.tips("分配成功！", "success", 1000, () => {
                  this.getSoData();
                });
              } else {
                IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
              }
            }
        );
      } else {
        IOT.tips("不存在新建状态的出库任务，请确认", "error", 1000, () => {
          IOT.hideOverlay();
        });
      }
    },
    // commitMerge() {
    //   IOT.showOverlay("保存中，请稍等...");
    //   let list = PF.JSON(this.multipleSelection);
    //   let billNos = [];
    //   IOT.getServerData(
    //     "/organizations/list",
    //     "get",
    //     { organizationId: list[0].organizationId },
    //     (ret) => {
    //       if (ret.code === 200) {
    //         let organization = ret.rows[0];
    //         IOT.getServerData(
    //           "/so/merge/tactics/list",
    //           "get",
    //           { soMergeTacticCode: organization.soMergeTacticCode },
    //           (ret) => {
    //             if (ret.code === 200) {
    //               if (ret.rows.length !== 1) {
    //                 IOT.tips(
    //                   "未查询到该货主下的合并策略!",
    //                   "error",
    //                   1000,
    //                   () => {
    //                     IOT.hideOverlay();
    //                   }
    //                 );
    //                 return false;
    //               }
    //               let soMergeTactic = ret.rows[0];
    //               let noMergerMsg = "";
    //               for (let i = 0; i < list.length; i++) {
    //                 if (soMergeTactic.billSource === 1) {
    //                   if (list[i].billSource !== list[0].billSource) {
    //                     noMergerMsg = "单据来源";
    //                   }
    //                 } /*else if(soMergeTactic.billSource === 2){
    //                 if(list[i].billSource !== list[0].billSource){
    //                   this.$confirm('单据来源不同,是否继续？', '提示', {
    //                     confirmButtonText: '确定',
    //                     cancelButtonText: '取消',
    //                     type: 'warning',
    //                     center: true
    //                   }).then(_ => {
    //                       this.deleteOrganization(id)
    //                   }).catch(_ => {
    //                     IOT.tips( '已取消合并!', 'error', 1000, () => {
    //                       IOT.hideOverlay();
    //                     });
    //                     return false
    //                   });
    //                 }
    //               }*/
    //                 if (soMergeTactic.deliveryTime === 1) {
    //                   if (list[i].deliveryTime !== list[0].deliveryTime) {
    //                     noMergerMsg = "qwe数量";
    //                   }
    //                 }
    //                 if (soMergeTactic.expectTimeFm === 1) {
    //                   if (list[i].expectTimeFm !== list[0].expectTimeFm) {
    //                     noMergerMsg = "预发数量FM";
    //                   }
    //                 }
    //                 if (soMergeTactic.expectTimeTo === 1) {
    //                   if (list[i].expectTimeTo !== list[0].expectTimeTo) {
    //                     noMergerMsg = "预发数量TO";
    //                   }
    //                 }
    //                 for (let j = 0; j < this.soUdfHs.length; j++) {
    //                   if (soMergeTactic[this.soUdfHs[j].paramCode] === 1) {
    //                     if (
    //                       list[i][this.soUdfHs[j].paramCode] !==
    //                       list[0][this.soUdfHs[j].paramCode]
    //                     ) {
    //                       noMergerMsg = this.soUdfHs[j].value;
    //                     }
    //                   }
    //                 }
    //                 billNos.push(list[i].billNo);
    //               }
    //               if (noMergerMsg === "") {
    //                 IOT.getServerData(
    //                   "/so/masters/merge",
    //                   "post",
    //                   { billNos: billNos },
    //                   (ret) => {
    //                     IOT.hideOverlay();
    //                     this.multipleSelection = [];
    //                     if (ret.code === 200) {
    //                       IOT.tips("合并成功！", "success");
    //                       this.getSoData();
    //                     } else {
    //                       IOT.tips(
    //                         ret.message || "服务器请求失败，稍后再试！",
    //                         "error"
    //                       );
    //                     }
    //                   }
    //                 );
    //               } else {
    //                 IOT.tips(
    //                   noMergerMsg + "不同,不能合并! 请重新选择",
    //                   "error",
    //                   1000,
    //                   () => {
    //                     IOT.hideOverlay();
    //                   }
    //                 );
    //               }
    //             } else {
    //               IOT.tips(
    //                 ret.message || "服务器请求失败，稍后再试！",
    //                 "error"
    //               );
    //             }
    //           }
    //         );
    //       } else {
    //         IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
    //       }
    //     }
    //   );
    // },

    commitMerge() {
      IOT.showOverlay("保存中，请稍等...");
      let list = PF.JSON(this.multipleSelection);
      let billNos = [];
      let noMergerMsg = "";
      for (let i = 0; i < list.length; i++) {
        // if (list[i].deliveryTime !== list[0].deliveryTime) {
        //   noMergerMsg = "qwe数量";
        // }
        billNos.push(list[i].billNo);
      }
      // console.log(JSON.stringify(billNos));
      // return;
      if (noMergerMsg === "") {
        IOT.getServerData(
            "/wave/masters/merge",
            "post",
            { billNos: billNos },
            ret => {
              IOT.hideOverlay();
              this.multipleSelection = [];
              if (ret.code === 200) {
                IOT.tips("合并成功！", "success");
                this.getSoData();
              } else {
                IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
              }
            }
        );
      } else {
        IOT.tips(
            noMergerMsg + "不同,不能合并! 请重新选择",
            "error",
            1000,
            () => {
              IOT.hideOverlay();
            }
        );
      }
    },

    enterSearch() {
      // var that = this;
      // 按下字符键触发--取消
      document.addEventListener("keydown", this.searchEvent);
      this.$once("hook:beforeDestroy", () => {
        document.removeEventListener("keydown", this.searchEvent);
      });
    },
    searchEvent(e) {
      if (e.keyCode === 13 || e.code === "Enter") {
        this.getSoData();
      }
    },

    //批量拣货
    batch() {
      // console.log("this.multipleSelection",this.multipleSelection);
      for (const argumentsKey in this.multipleSelection) {
        this.billNoList.push(this.multipleSelection[argumentsKey].billNo);
        console.log(this.multipleSelection[argumentsKey].billNo);
      }
      this.dialogVisible = true;
    },
    saveBillOutInfo() {
      console.log(this.date, "this.date");
      IOT.getServerData(
          "/transfer/saveBillOutInfo",
          "get",
          {
            date: this.date
          },
          ret => {
            if (ret.code === 200) {
              IOT.hideOverlay();
              IOT.tips("保存成功！", "success");
              this.getSoData();
            } else {
              IOT.hideOverlay();
              IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
            }
          }
      );
    },
    getUsers() {
      IOT.getServerData(
          "/ware/infos/findUserByWareId",
          "get",
          { wareId: 285 },
          (ret) => {
            if (ret.code === 200) {
              this.users = ret.rows;
              console.log(JSON.stringify(this.users));
            } else {
              IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
            }
          }
      );
    },


    //整单发货
    sendOut() {
      IOT.showOverlay("保存中，请稍等...");
      let list = PF.JSON(this.multipleSelection);
      //
      IOT.getServerData(
          "/so/masters/sendOut",
          "get",
          {
            billNo: list[0].billNo,
            wareId: null,
            weight: null
          },
          ret => {
            if (ret.code === 200) {
              IOT.hideOverlay();
              IOT.tips("保存成功！", "success");
              this.getSoData();
            } else {
              IOT.hideOverlay();
              IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
            }
          }
      );
    }
  },
  created() {
    this.getUsers();

    PF.getSysParamUdfData("soUdfHs", [], (data, udfs) => {
      this.soUdfHs = udfs;
    });
    this.getSoData();
    PF.getCarriers(rows => {
      this.carriers = rows;
    });
    PF.getSysParamUdfData("soUdfHs", [], (data, udfs) => {
      this.soUdfHs = udfs;
    });
    PF.getOrganizations(rows => {
      this.organizations = rows;
    });
    PF.getCustomers(rows => {
      this.customers = rows;
    });
    PF.getDataDictUdfData("soBillType", rows => {
      this.soBillTypes = rows;
    });


    // 输入元素自动搜索
    // this.enterSearch();



  },
  mounted() {}
};
</script>

<style scoped lang="less">
.soBill {
}

.warp {
  display: flex;
  justify-content: space-between;
}
</style>
